﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using SQLExecute;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

/// <summary>
/// Summary description for Common
/// </summary>
public class Common
{
    public static string strConnect = ConfigurationSettings.AppSettings["ConnectString"];
    DataSet ds;
    static DataTable[] dt=new DataTable[6];
	public Common()
	{
		//
		// TODO: Add constructor logic here
		//
        Init_Common();
	}
  

    static public void Init_Final_Dept(DropDownList cbRecruitmentDept)
    {
        cbRecruitmentDept.Items.Insert(0, new ListItem("VAS", "VAS"));
        cbRecruitmentDept.Items.Insert(1, new ListItem("VUS", "VUS"));
        cbRecruitmentDept.Items.Insert(2, new ListItem("EDU_CAPITAL", "EDU CAPITAL"));
        cbRecruitmentDept.Items.Insert(3, new ListItem("ELEARNING", "ELEARNING"));
        cbRecruitmentDept.Items.Insert(4, new ListItem("TUYENSINH", "TUYENSINH"));
        cbRecruitmentDept.Items.Insert(5, new ListItem("GIAOVU", "GIAOVU"));
    }
   
    public DataSet Get_Known_Us()
    {
        string sql = "select * from tbl_known_from where active='" + 1 + "' order by known_from";
         ds = SqlHelper.ExecuteDataset(strConnect, CommandType.Text, sql);

        return ds;
    }
    public void Init_City(DropDownList cbCity)
    {
        string sql = "select * from tbl_city";

        ds = SqlHelper.ExecuteDataset(strConnect, CommandType.Text, sql);


        cbCity.DataSource = ds.Tables[0];
        cbCity.DataTextField = "city_name";
        cbCity.DataValueField = "city_name";
        cbCity.DataBind();
        cbCity.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbCity.SelectedIndex = 0;
    }
    public void Init_Common()
    {
        ds = SqlHelper.ExecuteDataset(strConnect, "Select_Common");
        dt[0] = ds.Tables[0];
        dt[1] = ds.Tables[1];
        dt[2] = ds.Tables[2];
        dt[3] = ds.Tables[3];
        dt[4] = ds.Tables[4];
        dt[5] = ds.Tables[5];
        //dt[6] = ds.Tables[6];


    }
    public void Init_KnownUs(DropDownList cbKnownUs)
    {
        cbKnownUs.DataSource = dt[0];
        cbKnownUs.DataTextField = "known_from";
        cbKnownUs.DataValueField = "id";
        cbKnownUs.DataBind();
        cbKnownUs.SelectedIndex = 0;
        cbKnownUs.Items.Insert(0, new ListItem("CHOOSE ONE", "-1"));
        cbKnownUs.SelectedIndex = 0;
    }
    public void Init_District( DropDownList cbDistrictCurrent)
    {

        cbDistrictCurrent.DataSource = dt[1];
        cbDistrictCurrent.DataTextField = "district_name";
        cbDistrictCurrent.DataValueField = "id";
        cbDistrictCurrent.DataBind();
        cbDistrictCurrent.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));

        cbDistrictCurrent.SelectedIndex = 0;



    }
    public void Init_Graduation_Degree(DropDownList degree1, DropDownList degree2, DropDownList degree3, DropDownList degree4)
    {
        string sql = " select * from tbl_graduation_degree ";
        ds = SqlHelper.ExecuteDataset(strConnect, CommandType.Text, sql);

        degree1.DataSource = dt[2];
        degree1.DataTextField = "graduation_degree";
        degree1.DataValueField = "id";
        degree1.DataBind();
        degree1.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        degree1.SelectedIndex = 0;

        degree2.DataSource = dt[2];
        degree2.DataTextField = "graduation_degree";
        degree2.DataValueField = "id";
        degree2.DataBind();
        degree2.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        degree2.SelectedIndex = 0;

        degree3.DataSource = dt[2];
        degree3.DataTextField = "graduation_degree";
        degree3.DataValueField = "id";
        degree3.DataBind();
        degree3.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        degree3.SelectedIndex = 0;


        degree4.DataSource = dt[2];
        degree4.DataTextField = "graduation_degree";
        degree4.DataValueField = "id";
        degree4.DataBind();
        degree4.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        degree4.SelectedIndex = 0;


    }
   
    
    public void InitTypeOfTraining(DropDownList cbTypeOfTraining1,DropDownList cbTypeOfTraining2,DropDownList cbTypeOfTraining3,DropDownList cbTypeOfTraining4)
    {

        cbTypeOfTraining1.DataSource = dt[5];
        cbTypeOfTraining1.DataTextField = "typeoftraining";
        cbTypeOfTraining1.DataValueField = "id";
        cbTypeOfTraining1.DataBind();
        cbTypeOfTraining1.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbTypeOfTraining1.SelectedIndex = 0;

        cbTypeOfTraining2.DataSource = dt[5];
        cbTypeOfTraining2.DataTextField = "typeoftraining";
        cbTypeOfTraining2.DataValueField = "id";
        cbTypeOfTraining2.DataBind();
        cbTypeOfTraining2.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbTypeOfTraining2.SelectedIndex = 0;

        cbTypeOfTraining3.DataSource = dt[5];
        cbTypeOfTraining3.DataTextField = "typeoftraining";
        cbTypeOfTraining3.DataValueField = "id";
        cbTypeOfTraining3.DataBind();
        cbTypeOfTraining3.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbTypeOfTraining2.SelectedIndex = 0;

        cbTypeOfTraining4.DataSource = dt[5];
        cbTypeOfTraining4.DataTextField = "typeoftraining";
        cbTypeOfTraining4.DataValueField = "id";
        cbTypeOfTraining4.DataBind();
        cbTypeOfTraining4.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbTypeOfTraining4.SelectedIndex = 0;
    }
   
    public DataSet Select_Common()
    {
        ds = SqlHelper.ExecuteDataset(Common.strConnect, "Select_Common");

        return ds;
    }

    static public string Convert_DDMMYYYY_To_MMDDYYY(string s)
    {

        string month, day, year;

        int n1 = s.IndexOf("/", 0);

        day = s.Substring(0, n1);

        int n2 = s.IndexOf("/", n1 + 1);
        month = s.Substring(n1 + 1, n2 - (n1 + 1));

        year = s.Substring(s.Length - 4, 4);

        //n = s.IndexOf("/", n);
        //month=s.Substring(n+1,

        s = month + "/" + day + "/" + year;
        return s;
    }
    static public string Convert_MMDDYYYY_To_DDMMYYY(string s)
    {

        string month, day, year;

        int n1 = s.IndexOf("/", 0);

        month = s.Substring(0, n1);

        int n2 = s.IndexOf("/", n1 + 1);
        day = s.Substring(n1 + 1, n2 - (n1 + 1));

        year = s.Substring(s.Length - 4, 4);

        //n = s.IndexOf("/", n);
        //month=s.Substring(n+1,

        s = day + "/" + month + "/" + year;
        return s;
    }
    static public string Split_Number_Tele(string str)
    {
        string s = string.Empty;

        if (str.Length == 10)
        {
            s = str.Substring(0, 4) + " ";
            s += str.Substring(4, 3) + " ";
            s += str.Substring(str.Length - 3, 3);
        }

        return s;

    }
    public void Init_StudyPeriod(DropDownList cbStudyPeriod1,DropDownList cbStudyPeriod2
                                 ,DropDownList cbStudyPeriod3,DropDownList cbStudyPeriod4
                                 ,DropDownList cbStudyPeriod5,DropDownList cbStudyPeriod6
                                 ,DropDownList cbStudyPeriod7,DropDownList cbStudyPeriod8)
    { 
    
        int currentyear = DateTime.Now.Year;
        int i=0,j = 0;
        for (i = 1980,j=0; i <= currentyear + 1; i++,j++)
        {
            j = i;
            cbStudyPeriod1.Items.Insert(j-1980,new ListItem(i.ToString(),i.ToString()));
            cbStudyPeriod2.Items.Insert(j-1980, new ListItem(i.ToString(), i.ToString()));
            cbStudyPeriod3.Items.Insert(j-1980, new ListItem(i.ToString(), i.ToString()));
            cbStudyPeriod4.Items.Insert(j-1980, new ListItem(i.ToString(), i.ToString()));
            cbStudyPeriod6.Items.Insert(j-1980, new ListItem(i.ToString(), i.ToString()));
            cbStudyPeriod7.Items.Insert(j-1980, new ListItem(i.ToString(), i.ToString()));
            cbStudyPeriod8.Items.Insert(j-1980, new ListItem(i.ToString(), i.ToString()));            
        }
        cbStudyPeriod1.Items.Insert(0, new ListItem("from", "from"));
        cbStudyPeriod3.Items.Insert(0, new ListItem("from", "from"));
        cbStudyPeriod5.Items.Insert(0, new ListItem("from", "from"));
        cbStudyPeriod7.Items.Insert(0, new ListItem("from", "from"));

        cbStudyPeriod2.Items.Insert(0, new ListItem("to", "to"));
        cbStudyPeriod4.Items.Insert(0, new ListItem("to", "to"));
        cbStudyPeriod6.Items.Insert(0, new ListItem("to", "to"));
        cbStudyPeriod8.Items.Insert(0, new ListItem("to", "to"));


    }


    

    static public void SetConnectionInfo(Tables tables)
    {
       // TableLogOnInfo logOnInfo = new TableLogOnInfo();

       // logOnInfo = Report.Database.Tables[table].LogOnInfo;

        ConnectionInfo connectionInfo = new ConnectionInfo();
        connectionInfo.ServerName = ".";
        connectionInfo.DatabaseName = "hr";
        connectionInfo.UserID = "sa";
        connectionInfo.Password ="vusetsc@2011";

        foreach (CrystalDecisions.CrystalReports.Engine.Table tb in tables)
        {
            TableLogOnInfo tableLogOnInfo = tb.LogOnInfo;
            tableLogOnInfo.ConnectionInfo = connectionInfo;
            tb.ApplyLogOnInfo(tableLogOnInfo);
        }

    }
}
